{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "a0520de0",
   "metadata": {},
   "outputs": [],
   "source": [
    "info = {\n",
    "      \"stu1801\":\"ZiQi\",\n",
    "      \"stu1802\":\"XiaoFeng\",\n",
    "      \"stu1803\":\"LiuYu\"\n",
    "  }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "cc8934bd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stu1801': 'ZiQi', 'stu1802': 'XiaoFeng', 'stu1803': 'LiuYu'}"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "ef72866e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stu1801\n",
      "stu1802\n",
      "stu1803\n"
     ]
    }
   ],
   "source": [
    "# 循环遍历字典\n",
    "# i 是 item 在字典循环中打印的是什么？ Key\n",
    "# 我想循环遍历整个内容怎么做？\n",
    "for i in info:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "747afb6d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stu1801 ZiQi\n",
      "stu1802 XiaoFeng\n",
      "stu1803 LiuYu\n"
     ]
    }
   ],
   "source": [
    "# 循环遍历整个字典的 items\n",
    "for k,v in info.items():\n",
    "    print(k,v)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "14b022fd",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 实践 1: stu1801 中 取出数字， 作为新的字典Key\n",
    "new_info = {}\n",
    "for k,v in info.items():\n",
    "    # 用字典新增的方式创建字典\n",
    "    new_info[k[3:]] = v"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "22bfae9b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'1801': 'ZiQi', '1802': 'XiaoFeng', '1803': 'LiuYu'}"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "d4d199b2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 实践2: value 我也想变，所有字母大写\n",
    "new_info = {}\n",
    "for k,v in info.items():\n",
    "    # 用字典新增的方式创建字典\n",
    "    new_info[k[3:]] = v.upper()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "b43d3245",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'1801': 'ZIQI', '1802': 'XIAOFENG', '1803': 'LIUYU'}"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "7f8f40c0",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 实践3: 让new_info Key 由 '1801' => 1801\n",
    "new_info = {}\n",
    "for k,v in info.items():\n",
    "    # 用字典新增的方式创建字典\n",
    "    new_info[int(k[3:])] = v.upper()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "f005d9e4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1801: 'ZIQI', 1802: 'XIAOFENG', 1803: 'LIUYU'}"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1ecf8481",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
